package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.Hsgt;
import com.stylefeng.guns.modular.system.service.IHsgtService;
import com.stylefeng.guns.modular.system.warpper.HsgtWarpper;

/**
 * 沪深股通持股控制器
 *
 * @author fengshuonan
 * @Date 2018-06-19 18:04:38
 */
@Controller
@RequestMapping("/hsgt")
public class HsgtController extends BaseController {

    private String PREFIX = "/system/hsgt/";

    @Autowired
    private IHsgtService hsgtService;

    /**
     * 跳转到沪深股通持股首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "hsgt.html";
    }

    /**
     * 跳转到添加沪深股通持股
     */
    @RequestMapping("/hsgt_add")
    public String hsgtAdd() {
        return PREFIX + "hsgt_add.html";
    }

    /**
     * 跳转到修改沪深股通持股
     */
    @RequestMapping("/hsgt_update/{hsgtId}")
    public String hsgtUpdate(@PathVariable Integer hsgtId, Model model) {
        Hsgt hsgt = hsgtService.selectById(hsgtId);
        model.addAttribute("item",hsgt);
        LogObjectHolder.me().set(hsgt);
        return PREFIX + "hsgt_edit.html";
    }

    /**
     * 获取沪深股通持股列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(required = false) String date,@RequestParam(required = false) String dm,@RequestParam(required = false) Integer hsgtType) {
    	Page<Hsgt> page = new PageFactory<Hsgt>().defaultPage();
    	List<Map<String, Object>> gdhs = hsgtService.selectMapsByDm(page,date,dm,hsgtType);
    	page.setRecords((List<Hsgt>) new HsgtWarpper(gdhs).warp());
        return super.packForBT(page);
    }

    /**
     * 新增沪深股通持股
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Hsgt hsgt) {
        hsgtService.insert(hsgt);
        return SUCCESS_TIP;
    }

    /**
     * 删除沪深股通持股
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer hsgtId) {
        hsgtService.deleteById(hsgtId);
        return SUCCESS_TIP;
    }

    /**
     * 修改沪深股通持股
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Hsgt hsgt) {
        hsgtService.updateById(hsgt);
        return SUCCESS_TIP;
    }

    /**
     * 沪深股通持股详情
     */
    @RequestMapping(value = "/detail/{hsgtId}")
    @ResponseBody
    public Object detail(@PathVariable("hsgtId") Integer hsgtId) {
        return hsgtService.selectById(hsgtId);
    }
}
